
{% extends 'base.html' %}

{% block content %}
<h2 class="sub-header">展示物资表</h2>
    <a href="{%  url 'app01:Property_add'%}" class="btn btn-sm btn-primary">添加</a>
    <div  class="table-responsive">
        <table class="table table-striped">
            <thead>
            <tr>
                <th>序号</th>
                <th>名称</th>
                <th>编号</th>
                <th>购买时间</th>
                <th>所属实验室</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
                    {% for Property in Property_all %}
                        <tr>
                            <td>{{ forloop.counter }}</td>
                            <td>{{ Property.material_name }}</td>
                            <td>{{ Property.material_number }}</td>
                            <td>{{ Property.buy_time }}</td>
                            <td>{{ Property.Experiment.name }}</td>
                            <td>
                                <a class="btn btn-danger btn-sm" href="{% url 'app01:Property_del' Property.id %}">删除</a>
                                <a class="btn btn-success btn-sm" href="{% url 'app01:Property_edit' Property.pk  %}">修改</a>
                            </td>
                        </tr>

                    {% endfor %}
            </tbody>
        </table>
    </div>
{% endblock %}


{% block js %}
    <script>
        $('.btn-danger').click(function () {
            swal({
                title: "是否确定要删除?",
                text: "一旦删除，数据就无法恢复!",
                icon: "warning",
                buttons: true,
                dangerMode: true,
            })
                .then((willDelete) => {
                    if (willDelete) {

                        $.ajax({
                            url: $(this).attr('url'),
                            success: (res) => {
                                if (res.status === 200) {
                                    $(this).parent().parent().remove()
                                } else {
                                    swal("出现了错误，无法删除!");
                                }
                            }
                        })


                        swal("恭喜! 你的数据已经被删除了!", {
                            icon: "success",
                        });
                    } else {
                        swal("你的文件没有被删除!");
                    }
                });
        })
    </script>


{% endblock %}